package com.qf.business.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.business.goods.mapper.GoodsSortNormsMapper;
import com.qf.business.goods.service.GoodsSortNormsService;
import com.qf.data.goods.entity.GoodsSortNorms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * (GoodsSortNorms)表服务实现类
 *
 * @author makejava
 * @since 2022-07-07 00:03:35
 */
@Service
public class GoodsSortNormsServiceImpl extends ServiceImpl<GoodsSortNormsMapper, GoodsSortNorms> implements GoodsSortNormsService {

    @Autowired
    private GoodsSortNormsMapper goodsSortNormsMapper;

    @Override
    public int updateSortNorms(Long sortId, String[] normsIds) {
        //1、根据分类删除 管理的规格记录
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("sort_id",sortId);
        goodsSortNormsMapper.delete(queryWrapper);

        //2、设置分类下的规格
        if(normsIds != null || normsIds.length > 0){
            for (String normsId : normsIds) {
                GoodsSortNorms goodsSortNorms = new GoodsSortNorms();
                goodsSortNorms.setSortId(sortId);
                goodsSortNorms.setNormsId(Long.parseLong(normsId));

                //保存
                goodsSortNormsMapper.insert(goodsSortNorms);
            }
        }

        return 1;
    }
}

